package com.yuexunit.finance.project.action.v1.dto;

import java.util.ArrayList;
import java.util.List;

import com.yuexunit.finance.project.entity.FinanceMaterialEntity;
import com.yuexunit.finance.project.entity.lexicon.FinanceSegmentEnum;
import com.yuexunit.finance.project.service.FinanceMaterialService;
import com.yuexunit.inject.ComponentFactory;

/**
 * @author zeng hui wu 2015年10月8日
 */
public class FinanceMaterialCastor {

	/**  */
	public static List<FinanceMaterialEntity> fromFinanceMaterialArray(Long financeId, Long segmentId, FinanceSegmentEnum segment, String[] materialStrings) {
		List<FinanceMaterialEntity> financeMaterialList = new ArrayList<FinanceMaterialEntity>();
		for (int i = 0; i < materialStrings.length; i++) {
			FinanceMaterialEntity materialEntity = new FinanceMaterialEntity();
			materialEntity.setFinanceId(financeId);
			materialEntity.setSegmentId(segmentId);
			materialEntity.setFinanceSegment(segment);
			materialEntity.setFileUuid(materialStrings[i]);
			financeMaterialList.add(materialEntity);
		}
		return financeMaterialList;
	};

	/** 获取融资信息环节的附件,以逗号分割返回 */
	public static String toSegmentMaterials(Long financeId, Long segmentId, FinanceSegmentEnum segment) {
		FinanceMaterialService financeMaterialService = ComponentFactory.loadClass(FinanceMaterialService.class);
		List<FinanceMaterialEntity> materialList = financeMaterialService.inquireFinanceMaterialList(financeId, segmentId, segment);
		StringBuffer sb = new StringBuffer();
		for (FinanceMaterialEntity material : materialList) {
			if (sb.length() > 0) {
				sb.append(",");
			}
			sb.append(material.getFileUuid());
		}
		return sb.toString();
	}
}
